import { reqGetBannerList, reqGetCategoryList, reqGetFloorList } from "@/api";

const state = {
  categoryList:[],
  bannerList:[],
  floorList:[],
};
const mutations = {
  SET_CATEGORYLIST(state,categoryList){
    state.categoryList = categoryList;
  },
  SET_BANNERLIST(state,bannerList){
    state.bannerList = bannerList;
  },
  SET_FLOORLIST(state,floorList){
    state.floorList = floorList;
  }
};
const actions = {
  async getCategoryList({commit}){
    try {
      // result=promise的值
      const result = await reqGetCategoryList();
      if (result.code === 200) {
        commit('SET_CATEGORYLIST',result.data)
      }else {
        alert('请求成功，但是获取数据失败');
      }     
    } catch (error) {
      alert('请求失败');
    }
  },

  async getBannerList({commit}){
    try {
      const result = await reqGetBannerList();
      if(result.code === 200) {
        commit('SET_BANNERLIST',result.data);
      }else {
        alert('请求成功，但获取数据失败');
      }
    } catch (error) {
      alert('请求失败');
    }
    
  },

  async getFloorList({commit}) {
    try {
      const result = await reqGetFloorList();
      if (result.code === 200){
        commit('SET_FLOORLIST',result.data);
      }else {
        alert('请求成功，但是获取数据失败');
      }
    } catch (error) {
      alert('请求失败');
    }
  }
};
const getters = {};

export default {
  state,
  mutations,
  actions,
  getters,
}